#!/bin/bash

echo file path $TARGET_PATH
install(){
    if [ ! -d $TARGET_PATH ]; then
      mkdir -p $TARGET_PATH
    fi
    echo "解压文件到根目录"
    tar zxvf frontend.tar.gz

    if [ ! -d $TARGET_PATH/admin-web ]; then
        echo "admin-web backup and copy new version"
        mv $TARGET_PATH/admin-web $TARGET_PATH/admin-web-bat
    fi

    cp -rf  admin-web $TARGET_PATH/
    echo "copy admin-web to $TARGET_PATH successful"
    if [ ! -d $TARGET_PATH/components-web ]; then
        echo "components-web backup "
        mv $TARGET_PATH/components-web $TARGET_PATH/components-web-bat
    fi
    cp -rf  components-web $TARGET_PATH/
    echo "copy components-web to $TARGET_PATH successful"

    exit 0
}


uninstall(){
    if [ ! -d $TARGET_PATH/admin-web ]; then
        rm -rf $TARGET_PATH/admin-web
        echo "删除admin-web文件夹成功"
    fi

    if [ ! -d $TARGET_PATH/components-web ]; then
        rm -rf $TARGET_PATH/components-web
        echo "删除components-web文件夹成功"
    fi
    exit 0
}


# 主函数
main()
{
 case "$1" in
 install)  install;;
 uninstall)  uninstall;;
 *)        echo "command param error ! see follow help "; help;;
 esac
}

main $1